<?php

function printNews($work_description, $work_id, $type_img, $work_name, $region, $user_name, $req2) {


    switch ($type_img) {
        case 0 :
            $ext = 'png';
            break;
        case 1 :
            $ext = 'jpg';
            break;
        case 2 :
            $ext = 'jpeg';
            break;
        default :
            $ext = '';
            break;
    }

    echo '<span class="template_box_work">';

    echo '<img class="template_img" src="' . URL_IMG . '/works/' . $work_id . '.' . $ext . '" alt="" />';

    $region_w = regions($region);

    echo '
    <span class="template_right">
    <span class="template_span">Nom de l\'oeuvre:  <input class="template_input" type="text" name="work_name' . $work_id . '" value= "' . $work_name . '"></span>
    <span class="template_span">Première photo de l\'oeuvre (mise en avant):<input type="file" name="photo' . $work_id . '" ></span>
    <span class="template_span">Deuxième photo de l\'oeuvre (facultative):<input type="file" name="photob' . $work_id . '" ></span>';


    echo '<span class="template_span">Auteur de l\'article :<select multiple name="user_name' . $work_id . '">
               ';
    while ($donnees = $req2->fetch(PDO::FETCH_ASSOC)) {
        $name_autor = $donnees['user_name'];
        if ($user_name != $name_autor) {
            echo'  <OPTION> ' .$name_autor . '';
        } else {
            echo'  <OPTION selected> ' . $name_autor . '';
        }
    }
    echo' </select></span></span>';
    echo '<textarea class="template_input_text" name="description' . $work_id . '" id="visu' . $work_id . '" >' . $work_description . '</textarea>';
    $i = 0;
    echo '<span class="template_span">Region de l\'oeuvre :<select multiple name="id_region' . $work_id . '">';
    while ($i < 21) {
        $nm_region = regions($i);
        if ($nm_region != $region_w) {
            echo'  <OPTION> ' . $nm_region . '';
        } else {
            echo '<OPTION selected> ' . $nm_region . '';
        }
        $i++;
    } echo '  </span> ';
    echo'     </select>    <input type="button" value="valider"  onClick= "envoi_form(' . $work_id . ');" >
                              <input class="button" type="button" value="Supprimer" name = "delete"  onClick= "envoi_form_delete(' . $work_id . ');" >
    ';
    echo '</span></span>';
}

//}  Nom Region : <input type="text" name="artist_name'.$work_id.' value="'.$region.'">
function option_work($name, $slide_name) {
    echo'<option>' . $name . '';
    if ($name == $slide_name) {
        echo'<OPTION selected>' . $name . '';
    }
}

function start_form() {

    echo '<form action="' . URL_ROOT . 'update-work" method="post" name="form2" id="form2" enctype="multipart/form-data">
';
}

//   echo '<div class="send_form"><form action="'.URL_ROOT.'update-new/form-1-new_id-'.$news_id.'" method="post"  enctype="multipart/form-data">




function end_button() {

    echo'<button onClick="ClicBouton()"> Cliquez moi !</button> 
';
}

function end_form() {

    echo'
';
    //<input class="button" type="submit" value="Valider" id= "form" name ="envoyer"> 
}

?>
